<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../js/themes/icon.css">
<script type="text/javascript" src="../js/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"charset="utf-8"></script>
<script type="text/javascript" src="../js/locale/easyui-lang-zh_CN.js"charset="utf-8"></script>
	<script type="text/javascript">
		$(function(){
			$('#tt').datagrid({
				width:1250,
				height:350,
				url:'',
				singleSelect:false,
				rownumbers:true,
			    selectOnCheck: true,
			    checkOnSelect: true,
			    fit:false,
				columns:[[
				{field:'flag',title:'选择标志',width:80,checkbox:true},
				{field:'credencetype',title:'凭证类别',width:100, editor:{type:'text', options:{required: true }}},
				{field:'credenceP',title:'单据类型',width:145,editor:{type:'text', options:{required: true }}},
				{field:'credenceno',title:'单据号',width:145,editor:{type:'text', options:{required: true }}},
				{field:'credenceDate',title:'日期',width:145,editor:{type:'text', options:{required: true }}},
				{field:'credenceCusno',title:'客户编码',width:144,editor:{type:'text', options:{required: true }}},
				{field:'credenceCus',title:'客户',width:120,editor:{type:'text', options:{required: true }}},
				{field:'credenceMc',title:'借方金额',width:140,editor:{type:'text', options:{required: true }}},
				{field:'credenceMd',title:'贷方金额',width:140,editor:{type:'text', options:{required: true }}},
				{field:'',tite:'',width:120,align:'center',
	                formatter:function(value,row,index){
	                
	                    	 var s = '<a href="#" onclick="editrowb(this)">编辑</a> ';
		                     var c = '<a href="#" onclick="cancelrowb(this)">取消</a>';
		                     var e = '<a href="#" onclick="saverowb(this)">保存</a> ';
	                         return s+c+e;
	                 
	                }
	            }
				 ]],
			});
	});
</script>

<title>Insert title here</title>
<style>
	#d1{
		margin-top: 95px;
		text-align:center;
	}
#d2{
	margin-top: 40px;
}
#d2 table{border-right:1px solid black;border-bottom:1px solid black;} 
#d2 table td{border-left:1px solid black;border-top:1px solid black;width: 100px;
  		  height: 28px;text-align: center;} 
#d3{
	width: 1100px;
	margin: 45px auto;
}
#d4{
	margin-left: 1274px;
	margin-top: 45px;
}
#dd1{
	margin-top: -56px;
}
#s1{
	margin-left: 1486px;
}
</style>
<script type="text/javascript">

 function insertLine(){
		var row = $('#tt').datagrid('getSelected');
	    var index = $('#tt').datagrid('getRowIndex',row);
		if (row){
			var index = $('#tt').datagrid('getRowIndex', row);
		} else {
			index = 0;
		}
		$('#tt').datagrid('appendRow', {
			index: index,
			row:{
			}
		});
	

		
 };
 
   function deleteLine(){
	   var row = $('#tt').datagrid('getSelected');
	   var index = $('#tt').datagrid('getRowIndex',row);
	   if(index==-1){
		   $.messager.alert("","没有数据可删除");
	   }
	   else{
		   $.messager.confirm('Confirm','确定删除?',function(r){
		     if(r){
		    	 $('#tt').datagrid('deleteRow',index);
		     }    
		    });

	   }
   };
   function saverowb(index){
	   var row = $('#tt').datagrid('getSelected');
		 var index = $('#tt').datagrid('getRowIndex',row);
	     $('#tt').datagrid('endEdit',index);
	     $('#tt').datagrid('uncheckRow',index);
	};
	function cancelrowb(index){
		 var row = $('#tt').datagrid('getSelected');
		 var index = $('#tt').datagrid('getRowIndex',row);
	    $('#tt').datagrid('cancelEdit',index);
	};
	function editrowb(index){
		 var row = $('#tt').datagrid('getSelected');
		 var index = $('#tt').datagrid('getRowIndex',row);
	     $('#tt').datagrid('beginEdit', index);
	};
	function updateRecord(){
		var rows=new Array()
        rows = $('#tt').datagrid('getChecked');
	    for(var row in rows) {
			  
			 $.ajax({
		           type: "POST",
		           url:"<%=path%>/main/save/cre",
				   data : {
							    "credencetype": rows[row].credencetype, //凭证类别
							    "credenceP" : rows[row].credenceP,//单据类型
	                            "credenceno" : rows[row].credenceno,//单据号
	                            "credenceDate": rows[row].credenceDate,//日期
								"credenceCus":  rows[row].credenceCus,//客户
								"credenceCusno": rows[row].credenceCusno,//客户编码
								"credenceTotal": rows[row].credenceTotal//金额
						},
							async : false,
							success : function(data) {
								var data = eval('(' + data + ')');
							    var num = data.status;
								if (num == 0) {
	                             
									$.messager.alert("","填加成功");
	                          	 
								}

							}
						});
			 
			 }
};
</script>
</head>

<body>
	
	  <div id="dd1">
				<span id="s1"><a id="sp" href="#" class="easyui-linkbutton" >审批</a></span>
				<span id="s2"><a id="zf" href="#" class="easyui-linkbutton" >作废</a></span> 
	  </div>
    	<div id="d1"><h2>生成凭证</h2></div>
      <div id="d3">
		        <table id="cd">
		          <tr><td><a id="zj" href="#" class="easyui-linkbutton" onclick="insertLine()"/>增加</td>
		              <td><a id="sc" href="#" class="easyui-linkbutton" onclick="deleteLine()"/>删除</td></tr>
		        </table>

				<table id="tt">
				</table>
		</div>
		<div id="d4">
			<a id="btn" href="#" class="easyui-linkbutton" onclick="updateRecord()">生成凭证</a>
		</div>
		
</body>
</html>